# Maintainer: Justin Kromlinger <hashworks@archlinux.org>
# Contributor: genofire

pkgname=ovenmediaengine
pkgver=0.15.8
pkgrel=1
pkgdesc='Open-source streaming video service with sub-second latency'
arch=('loong64' 'x86_64')
url='https://ovenmediaengine.com'
license=('AGPL3')
# See https://github.com/AirenSoft/OvenMediaEngine/blob/master/misc/prerequisites.sh#L455
depends=(
	'openssl>=3'
	'libsrtp'
	'srt'
	'opus'
	'ffmpeg'
	'jemalloc'
	'pcre2'
	'hiredis'
)
optdepends=(
	'libva'
	'intel-gmmlib'
	'intel-media-sdk'
	'intel-media-driver'
	'cuda-tools'
	'ffnvcodec-headers'
)
makedepends=(
	'bc'
	'nasm'
	'x264'
	'x265'
	'libvpx'
	'fdkaac'
)
source=(
	"${pkgname}-${pkgver}.tar.gz::https://github.com/AirenSoft/OvenMediaEngine/archive/refs/tags/v${pkgver}.tar.gz"
	"ovenmediaengine.service"
)
sha512sums=('fcebe9fee7fdc387e574817c4d631d149115abd913eee0fcab33d41508d75b926f026f5fa564fbaf51b00ed1b8b5b13c2891fc9135848f8223e45866d8b96089'
            'c5c4615d4c50a55c6fea177a1bc73b13d1365224c4e102067e45ce956741cb95366ec3b16cdec8932083c923910794e9164b0f9a25a6b0e2f186557fac3e42f1')

backup=(
	'etc/ovenmediaengine/Server.xml'
	'etc/ovenmediaengine/Logger.xml'
)

prepare() {
	cd "OvenMediaEngine-${pkgver}"

	# Assets take up ~13MB of space
	rm -Rf docs/.gitbook
	find docs -type f -name "*.md" -exec sed -i "s|.gitbook/assets|https://raw.githubusercontent.com/AirenSoft/OvenMediaEngine/v${pkgver}/docs/.gitbook/assets|g" {} +
}

build() {
	cd "OvenMediaEngine-${pkgver}/src"

	DISABLE_CUSTOM_LIBRARY_PATHS=true \
	make release
}

package()  {
	install -D -m0644 "ovenmediaengine.service" "${pkgdir}/usr/lib/systemd/system/ovenmediaengine.service"

	cd "OvenMediaEngine-${pkgver}"

	install -D -m0755 "src/bin/RELEASE/OvenMediaEngine" "${pkgdir}/usr/bin/OvenMediaEngine"

	install -D -m0644 "misc/conf_examples/Origin.xml" "${pkgdir}/etc/ovenmediaengine/Server.xml"
	install -D -m0644 "misc/conf_examples/Logger.xml" "${pkgdir}/etc/ovenmediaengine/Logger.xml"

	install -D -m0644 "LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"

	mkdir -p "${pkgdir}/usr/share/doc"
	cp -a docs "${pkgdir}/usr/share/doc/${pkgname}"
	cp -a misc/conf_examples "${pkgdir}/usr/share/doc/${pkgname}/conf_examples"
}
